<template>
  <div class="building-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <div class="search-label">企业名称：</div>
      <el-input v-model="params.name" clearable placeholder="请输入内容" class="search-main" @clear="getList2" />
      <el-button type="primary" @click="getList2">查询</el-button>
    </div>
    <div class="create-container">
      <el-button type="primary" @click="add" >添加企业</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table style="width: 100%" :data="list">
        <el-table-column type="index" label="序号" />
        <el-table-column label="企业名称" width="320" prop="name" />
        <el-table-column label="联系人" prop="contact" />
        <el-table-column
          label="联系电话"
          prop="contactNumber"
        />
        <el-table-column label="操作">
          <template #default="scope">
            <!-- <el-button size="mini" type="text">添加合同</el-button> -->
            <el-button size="mini" type="text" @click="show(scope.row)">查看</el-button>
            <el-button size="mini" type="text" @click="edit(scope.row.id)">编辑</el-button>
            <el-button size="mini" type="text" @click="del(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div  class="box">
        <!-- 分页器的 -->
      <el-pagination
      :current-page="params.page"
      :page-sizes="[5,10, 15, 2]"
      :page-size="params.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      />
      </div>

    

  </div>
</template>



<script>
import { getEnterpriseListAPI, delEnterpriseAPI  } from '@/api/enterprise';
export default{
  name: 'Building',
  data(){
    return{

      total:0,
      list: [],

      params: {
        name:'',
        page: 1,
        pageSize: 10
      }, 
    }

  },

  mounted(){
    //加载请求
    this.getList()
  
  },

  methods: {

    del(id){
      //二次确认 =>调用接口=> 提示=>重新获取数据
      this.$confirm('确定删除吗？').then(() => {
          delEnterpriseAPI(id).then(() =>{
          
          this.$message.success('删除成功')
          this.getList()
        })
      }).catch(() =>{
        //取消
      })
    },


    edit(id){
      this.$router.push('/addEnterprise?id=' + id)
    },
   
    add(){
      //跳转到新页面
      this.$router.push('/addEnterprise')
    },
    

    handleCurrentChange(page) {
      console.log('页码变了', page)
      this.params.page = page
      this.getList()
    },
    handleSizeChange(pageSize) {
      console.log('每页条数变了', pageSize)
      this.params.pageSize = pageSize
      // this.params.page = 1
      this.getList()
    },
getList2(){
  this.params.page = 1
  getEnterpriseListAPI(this.params).then((res) => {
        console.log(res)  //存数据
        this.list=res.data.rows
        this.total=res.data.total
        
      })
},


    getList(){
      getEnterpriseListAPI(this.params).then((res) => {
        console.log(res)  //存数据
        this.list=res.data.rows
        this.total=res.data.total
        
      })
    }
  },



}
</script>

<style lang="scss" scoped>

.box{
//   //浮动
// float: right;


  //flex弹性容器  横向布局
  display: flex;
  //flex默认从左往右
  justify-content: flex-end;
  margin-top: 20px;
  margin-right: 20px;
}


.department-container {
  padding: 10px;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  ;
  padding-bottom: 20px;

  .search-label {
    width: 100px;
  }

  .search-main {
    width: 220px;
    margin-right: 10px;
  }
}
.create-container{
  margin: 10px 0px;
}
.page-container{
  padding:4px 0px;
  text-align: right;
}
.form-container{
  padding:0px 80px;
}
</style>

